import { Component, forwardRef, Input } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';

const ST_INPUT_AMOUNT_CONTROL_VALUE_ACCESSOR: any = {
  provide: NG_VALUE_ACCESSOR,
  // tslint:disable-next-line
  useExisting: forwardRef(() => IssueInputAmountComponent),
  multi: true,
};

@Component({
  selector: 'issue-input-amount',
  templateUrl: './issue-input-amount.component.html',
  styleUrls: ['./issue-input-amount.component.scss'],
  providers: [ST_INPUT_AMOUNT_CONTROL_VALUE_ACCESSOR],
})
export class IssueInputAmountComponent implements ControlValueAccessor {
  @Input() private width = '160px';
  @Input() private _valueInput: any = '';
  @Input() private readonly = false;

  set valueInput(value) {
    this._valueInput = value;
    this.propagateChange(this._valueInput);
  }
  get valueInput() {
    return this._valueInput;
  }
  public registerOnChange(fn: any) {
    this.propagateChange = fn;
  }
  public registerOnTouched(fn: any) {}
  public writeValue(newValue: any) {
    this.valueInput = newValue;
  }
  private propagateChange(_: any) {}
}
